package com.mzj.saas.mservice.smartlock.service.tianwanghulian;

import com.alibaba.fastjson.JSON;
import com.mzj.saas.mservice.smartlock.vo.tianwanghulian.TwhlCallBackVO;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

/**
 * 天网互联-事件回调
 */
@Service
public class SmartLockTwhlCallBackService {

    private static final Logger log = LoggerFactory.getLogger(SmartLockTwhlCallBackService.class);
    @Autowired
    private SmartLockTwhlEventHandleService smartLockTwhlEventHandleService;

    public String lockCallback(TwhlCallBackVO vo) {
        log.info("天网互联, 智能锁回调/事件url------vo={}", JSON.toJSONString(vo));
        try {
            Integer productType = vo.getProductType();
            if (productType != 1 ) {
                log.warn("不是门锁内容推送");
                return "ok";
            }

             switch (vo.getType()) {
                case 1:// 心跳日志
                    smartLockTwhlEventHandleService.lockOnlineCallBack(vo);
                    break;
                case 2:// 告警日志
                    smartLockTwhlEventHandleService.lockAlarm(vo);
                    break;
                case 4:// 开锁日志
                    smartLockTwhlEventHandleService.logEventHandle(vo);
                    break;
                default:
                    log.warn("天网互联, 智能锁回调事件处理不在该类型中 = {}", vo.getType());
                    break;
            }
            return "ok";
        } catch (Exception e) {
            log.error("天网互联, 智能锁回调事件异常" + e.getMessage(), e);
        }
        return "ok";
    }
}
